package com.linefly.online_car.Custom;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.linefly.online_car.R;


/**
 * Created by liheng on 2018/11/16.
 */

public class Custom_Dialog_shaixuan extends Dialog {

    private Context context;
    private TextView tv_sousuo,tv_shebei,tv_chepai;
    EditText et_shebei,et_chepai;
    private int type = 0;

    public Custom_Dialog_shaixuan(Context context1){

        super(context1, R.style.pagerDialog);
        context = context1;

    }

    public Custom_Dialog_shaixuan(Context context1,int type){

        super(context1, R.style.pagerDialog);
        context = context1;
        this.type = type;//栅栏的筛选和其他的不一样 type来区分

    }

    public interface OnClickListener{
        void onClick(String chepai,String shebei);
    }
    OnClickListener onClickListener;
    public void setOnClickListener(OnClickListener onClickListener){
        this.onClickListener = onClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getAttributes().gravity = Gravity.CENTER;
        setContentView(R.layout.item_dialog_shaixuan);


        //按空白处不能取消动画
        setCanceledOnTouchOutside(true);
        setCancelable(true);

        Window dialogWindow = getWindow();
                 WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                 DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用

                 lp.width = (int) (d.widthPixels * 0.7); // 宽度度设置为屏幕的0.5
                 lp.height = (int) (d.widthPixels * 0.5); // 高度设置为宽度的0.8

                 dialogWindow.setAttributes(lp);

        et_chepai = (EditText) findViewById(R.id.chepai);
        et_shebei = (EditText) findViewById(R.id.shebei);
        tv_shebei = (TextView)findViewById(R.id.tv_shebei);
        tv_chepai = (TextView)findViewById(R.id.tv_chepai);
        if(type == 1){
            tv_shebei.setVisibility(View.GONE);
            et_shebei.setVisibility(View.GONE);
            tv_chepai.setText("名称:");
        }
        tv_sousuo = (TextView)findViewById(R.id.sousuo);
        tv_sousuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListener.onClick(et_chepai.getText().toString(),et_shebei.getText().toString());


            }
        });


    }



}

